/**
 * 微信登录
 * @param  {object} info [用户信息]
 * @param  {function} successCallback [成功回调]
 * @param  {function} errorCallback [错误回调]
 */
function wxLogin(info, successCallback, errorCallback) {
  $.ajax({
    url: 'ajax/wxlogin',
    type: 'post',
    async: true,
    data: {
      openId: info.openid,
      unionId: info.unionid
    },
    dataType: 'json',
    success: function(data) {
      if (data.result != null) {
        console.log('ajax:登录成功');
        successCallback(data.result);
      }
      else {
        console.log('ajax:登录失败');
        errorCallback();
      }
    }
  });
}

/**
 * 微信注册
 * @param  {object} info [用户信息]
 * @param  {function} successCallback [成功回调]
 * @param  {function} errorCallback [错误回调]
 */
function wxRegister(info, successCallback, errorCallback) {

  $.ajax({
    url: 'ajax/wxregister',
    type: 'post',
    async: true,
    data: {
      nickName: info.nickname,
      avatar: info.headimgurl,
      sex: info.sex,
      openId: info.openid,
      unionId: info.unionid,
    },
    dataType: 'json',
    success: function(data) {
      if (data.returnCode == 0) {
        console.log('ajax:注册成功');
        successCallback(data.result);
      }
      else {
        console.log('ajax:注册失败');
        console.log(data.message);
        errorCallback();
      }
    }
  });
}
